package com.woniuxy.woniufp.common.model.utils;

import com.woniuxy.woniufp.common.model.constant.UserConstant;
import com.woniuxy.woniufp.common.model.vo.user.TokenVo;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

public class TokenUtiles {
    public static TokenVo getTokenVo(){
        HttpServletRequest request = ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest();
        //获取token的值
       /* String token = request.getHeader("token");
        JwtUtils jwtUtils = new JwtUtils();
        String id = jwtUtils.parseToken(token, UserConstant.TOKEN_USERID)+"";
        String userName = (String) jwtUtils.parseToken(token, UserConstant.TOKEN_USERNAME);
        String phone = (String) jwtUtils.parseToken(token, UserConstant.TOKEN_PHONE);*/

        String userId = request.getHeader(UserConstant.TOKEN_USERID);
        String userName = request.getHeader(UserConstant.TOKEN_USERNAME);
        String phone = request.getHeader(UserConstant.TOKEN_PHONE);

        TokenVo tokenVo = new TokenVo();
        tokenVo.setId(userId);
        tokenVo.setUserName(userName);
        tokenVo.setPhone(phone);
        return tokenVo ;
    }
}
